package format

type ResCode int64

const (
	CodeSuccess      ResCode = 1000 + iota // 1000
	CodeServerBusy                         // 1001
	CodeInvalidParam                       // 1002
	CodeUserExist
	CodeUserNotExist
	CodeInvalidPassword
	CodeNeedLogin
	CodeInvalidToken
	CodeSystemError
	CodeUserNameEmpty
	CodePasswordEmpty
	CodePasswordWrong
	CodeUserLoginFailed
	CodeUserForbidden
	CodeUserRegistFailed
	CodePasswordNotSame
	CodeDatabaseErr
	CodeUserIdNotExist
	CodeRoleNameIsNil
	CodeRoleNameIsExist
	CodeMenuTreeErr
)

var codeMsgMap = map[ResCode]string{
	CodeSuccess:         "成功",       //1000
	CodeServerBusy:      "服务繁忙",     //1001
	CodeInvalidParam:    "请求参数错误",   //1002
	CodeUserExist:       "用户已存在",    //1003
	CodeUserNotExist:    "用户不存在",    //1004
	CodeInvalidPassword: "用户名或密码错误", //1005

	CodeNeedLogin:        "需要登录",           //1006
	CodeInvalidToken:     "无效的token,请重新登录", //1007
	CodeSystemError:      "系统错误",           //1008
	CodeUserNameEmpty:    "用户名为空",          // 1009
	CodePasswordEmpty:    "密码为空",           // 1010
	CodePasswordWrong:    "密码错误",           // 1011
	CodeUserLoginFailed:  "登录错误",           // 1012
	CodeUserForbidden:    "玩家被禁止登录",        // 1013
	CodeUserRegistFailed: "用户注册失败",         // 1014
	CodePasswordNotSame:  "两次输入的密码不一致",     // 1015
	CodeDatabaseErr:      "数据库错误",          // 1016
	CodeUserIdNotExist:   "玩家id不存在",        // 1017
	CodeRoleNameIsNil:    "角色名为空",          // 1018
	CodeRoleNameIsExist:  "角色名已经存在",        // 1019
	CodeMenuTreeErr:      "获取目录树错误",        // 1020
}

func (c ResCode) Msg() string {
	msg, ok := codeMsgMap[c]
	if !ok {
		msg = codeMsgMap[CodeServerBusy]
	}
	return msg
}
